﻿using System;
using System.Data;
using System.Collections.Generic;
using HHModel;
using HHDALFactory;
using HHIDAL;
namespace HHBLL
{
	/// <summary>
	/// Roles
	/// </summary>
	public partial class Roles
	{
		private readonly IRoles dal=DataAccess.CreateRoles();
		public Roles()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			return dal.Exists(ID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(HHModel.Roles model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(HHModel.Roles model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			return dal.Delete(ID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			return dal.DeleteList(IDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HHModel.Roles GetModel(int ID)
		{
			
			return dal.GetModel(ID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
        //public HHModel.Roles GetModelByCache(int ID)
        //{
			
        //    string CacheKey = "RolesModel-" + ID;
        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(ID);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch{}
        //    }
        //    return (HHModel.Roles)objModel;
        //}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<HHModel.Roles> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<HHModel.Roles> DataTableToList(DataTable dt)
		{
			List<HHModel.Roles> modelList = new List<HHModel.Roles>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				HHModel.Roles model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new HHModel.Roles();
					if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="")
					{
						model.ID=int.Parse(dt.Rows[n]["ID"].ToString());
					}
					if(dt.Rows[n]["RoleName"]!=null && dt.Rows[n]["RoleName"].ToString()!="")
					{
					model.RoleName=dt.Rows[n]["RoleName"].ToString();
					}
					if(dt.Rows[n]["FunctionIntro"]!=null && dt.Rows[n]["FunctionIntro"].ToString()!="")
					{
					model.FunctionIntro=dt.Rows[n]["FunctionIntro"].ToString();
					}
					if(dt.Rows[n]["PagePowers"]!=null && dt.Rows[n]["PagePowers"].ToString()!="")
					{
					model.PagePowers=dt.Rows[n]["PagePowers"].ToString();
					}
					if(dt.Rows[n]["Sort"]!=null && dt.Rows[n]["Sort"].ToString()!="")
					{
						model.Sort=int.Parse(dt.Rows[n]["Sort"].ToString());
					}
					if(dt.Rows[n]["OpenState"]!=null && dt.Rows[n]["OpenState"].ToString()!="")
					{
						model.OpenState=int.Parse(dt.Rows[n]["OpenState"].ToString());
					}
					if(dt.Rows[n]["Creater"]!=null && dt.Rows[n]["Creater"].ToString()!="")
					{
					model.Creater=dt.Rows[n]["Creater"].ToString();
					}
					if(dt.Rows[n]["CreateTime"]!=null && dt.Rows[n]["CreateTime"].ToString()!="")
					{
						model.CreateTime=DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
					}
					if(dt.Rows[n]["LastUpdater"]!=null && dt.Rows[n]["LastUpdater"].ToString()!="")
					{
					model.LastUpdater=dt.Rows[n]["LastUpdater"].ToString();
					}
					if(dt.Rows[n]["LastUpdateTime"]!=null && dt.Rows[n]["LastUpdateTime"].ToString()!="")
					{
						model.LastUpdateTime=DateTime.Parse(dt.Rows[n]["LastUpdateTime"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

